package com.vision.core.cl.ui.component;

import java.util.Arrays;

import com.google.gwt.uibinder.client.UiConstructor;
import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.widget.core.client.form.SimpleComboBox;

/**
 * 
 * @author Mark
 *
 */
public class EnumComboBox<T extends Enum<T>> extends SimpleComboBox<T> {
	
	@UiConstructor
	public EnumComboBox() {
		super(new LabelProvider<T>() {
			@Override
			public String getLabel(T item) {
				return item.toString();
			}
		});
	}

	public EnumComboBox(LabelProvider<T> labelProvider) {
		super(labelProvider);
	}
	
	public EnumComboBox(T[] values) {
		this();
		loadValues(values);
	}
	
	public EnumComboBox(LabelProvider<T> labelProvider, T[] values) {
		this(labelProvider);
		loadValues(values);
	}
	
	protected void loadValues(T[] values) {
		add( Arrays.asList(values) );
	}
	
	protected String getText(T item) {
		return item.toString();
	}

}
